import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class Driver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration, "homework");
        job.setJarByClass(Driver.class);
        job.setMapperClass(HomeworkMapper.class);
        job.setReducerClass(HomeworkReducer.class);
        job.setMapOutputKeyClass(NumberBean.class);
        job.setMapOutputValueClass(NullWritable.class);
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(NumberBean.class);

        FileInputFormat.setInputPaths(job, new Path("src/main/resources/data"));
        FileOutputFormat.setOutputPath(job, new Path("src/main/resources/output"));

        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
